package com.zhiyou100.api.book_demo.dao;

import com.zhiyou100.api.book_demo.pojo.BookInfo;
import com.zhiyou100.api.book_demo.pojo.Category;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

//数据层的公共父类，主要用户初始化数据
public class BaseDao {
    //默认此map保存所有的图书类别以及对应的图书信息
    private static HashMap<Category, List<BookInfo>> booksMap = new HashMap<>();
    //初始化数据
    static {
//        booksMap = new HashMap<>();
        Category category = new Category("1001", "自然类");
        Category category2 = new Category("1002", "计算机类");
        Category category3 = new Category("1003", "文学类");
        BookInfo bookInfo = new BookInfo("100101", "动物世界", 89, "大冬", LocalDate.of(2020, 10, 01));
        BookInfo bookInfo1 = new BookInfo("100201", "Java基础", 90, "大刘", LocalDate.of(2021, 8, 01));
        BookInfo bookInfo2 = new BookInfo("100202", "Java进阶", 91, "大刘", LocalDate.of(2019, 7, 01));
        BookInfo bookInfo3 = new BookInfo("100203", "SpringBoot开发", 82, "老王", LocalDate.of(2020, 2, 01));
        BookInfo bookInfo4 = new BookInfo("100102", "动物大全", 70, "大冬", LocalDate.of(2020, 1, 01));
        BookInfo bookInfo5 = new BookInfo("100301", "三国", 56, "罗贯中", LocalDate.of(2018, 6, 01));
        BookInfo bookInfo6 = new BookInfo("100302", "红楼梦", 60, "曹雪芹", LocalDate.of(2021, 4, 01));
        BookInfo bookInfo7 = new BookInfo("100303", "梦三国", 61, "无名人士", LocalDate.of(2022, 01, 01));
        List<BookInfo> bookInfos = new ArrayList<>();
        bookInfos.add(bookInfo);
        bookInfos.add(bookInfo4);
        List<BookInfo> bookInfos2 = new ArrayList<>();
        bookInfos2.add(bookInfo1);
        bookInfos2.add(bookInfo2);
        bookInfos2.add(bookInfo3);
        List<BookInfo> bookInfos3 = new ArrayList<>();
        bookInfos3.add(bookInfo5);
        bookInfos3.add(bookInfo6);
        bookInfos3.add(bookInfo7);
        booksMap.put(category, bookInfos);
        booksMap.put(category2, bookInfos2);
        booksMap.put(category3, bookInfos3);
    }

    public static HashMap<Category, List<BookInfo>> getBooksMap() {
        return booksMap;
    }

    public static void setBooksMap(HashMap<Category, List<BookInfo>> booksMap) {
        BaseDao.booksMap = booksMap;
    }
}
